﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;

namespace AMOOF {
    class PressButton : Panel {
        
        public string MouseOverImage { set; get; }
        public string ClickedImage { set; get; }
        public string InactiveImage { set; get; }
        public int Index { set; get; }
        public string Text { set; get; }
        public Font Font { set; get; }

        public PressButton() {
            InitializeComponents();
        }

        

        private void InitializeComponents() {
            Width = 200;
            Height = 54;
            this.Font = new Font("Arial", 11, FontStyle.Regular);
            this.BackgroundImageLayout = ImageLayout.Stretch;

            MouseOverImage = "button_hover_200x54";
            ClickedImage = "button_clicked_200x54";
            InactiveImage = "button_inactive_200x54";
            this.MouseDown += new MouseEventHandler(PressButton_MouseDown);
            this.MouseUp += new MouseEventHandler(PressButton_MouseUp);
            this.MouseEnter += new EventHandler(PressButton_MouseEnter);
            this.MouseLeave += new EventHandler(PressButton_MouseLeave);
        }

        protected override void OnPaint(PaintEventArgs e) {
            base.OnPaint(e);
            //Text = "Optimize Models";
            //NavFont = new Font("Arial", 13, FontStyle.Bold);
            SizeF size = new SizeF();
            size = e.Graphics.MeasureString(Text, Font);
            float x = (this.Width - size.Width) / 2;
            float y = ((this.Height - size.Height) / 2);
            Brush b = this.Enabled ? Brushes.White : Brushes.Gray;

            e.Graphics.DrawString(Text, Font, b, x, y, StringFormat.GenericDefault);
        }

        private bool MouseIn(Control c, MouseEventArgs e) {
            if (e.X > 0 &&
                e.X < c.Width &&
                e.Y > 0 &&
                e.Y < c.Height) {
                return true;
            }

            return false;
        }

        private void PressButton_MouseDown(object sender, MouseEventArgs e) {
            this.BackgroundImage = (Bitmap)Properties.Resources.ResourceManager.GetObject(ClickedImage);
        }

        private void PressButton_MouseUp(object sender, MouseEventArgs e) {
            this.BackgroundImage = (Bitmap)Properties.Resources.ResourceManager.GetObject(InactiveImage);
        }
        

        private void PressButton_MouseEnter(object sender, EventArgs e) {
            this.BackgroundImage = (Bitmap)Properties.Resources.ResourceManager.GetObject(MouseOverImage);
        }

        private void PressButton_MouseLeave(object sender, EventArgs e) {
            this.BackgroundImage = (Bitmap)Properties.Resources.ResourceManager.GetObject(InactiveImage);
        }
    }
}
